


proc compfire
    if isahit = 1 then
	if (hitx + 1 < 11) then
	    userx := hitx + 1
	    usery := hity
	end if
	isahit := 2
    elsif isahit = 2 then
	if (hitx - 1 > 0) then
	    userx := hitx - 1
	    usery := hity
	end if
	isahit := 3
    elsif isahit = 3 then
	if (hity + 1 < 11) then
	    userx := hitx
	    usery := hity + 1
	end if
	isahit := 4
    elsif isahit = 4 then
	if (hity - 1 > 0) then
	    userx := hitx
	    usery := hity - 1
	end if
	isahit := 0
    else
	loop
	    userx := Rand.Int (1, 10)
	    usery := Rand.Int (1, 10)
	    exit when userloc (userx, usery) = 0 or userloc (userx, usery) = 1
	end loop
    end if

    loop
	if userloc (userx, usery) = 1 then
	    putout ("Comp: HIT!")
	    coloursq (GridWin, red, userx, usery)
	    userloc (userx, usery) := 2
	    isahit := 1
	    hitx := userx
	    hity := usery
	    exit
	elsif userloc (userx, usery) = 2 or userloc (userx, usery) = 3 then
	    putout ("Comp: Already fired there!")
	    exit
	else
	    coloursq (GridWin, blue, userx, usery)
	    userloc (userx, usery) := 3
	    putout ("Comp: Miss")
	    exit
	end if
    end loop
end compfire
